package com.yw.common.core.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import com.yw.common.core.db.dao.IUpdateDao;
import com.yw.common.core.db.dao.impl.DefaultUpdateDaoImpl;
import com.yw.common.core.db.dao.proxy.DefaultUpdateDaoProxy;

/**
 * dbm解析工具
 * @author aoshiguchen
 * @time 2015-12-06
 */

public final class DbmUtil {
	
	public static  Map<String,IUpdateDao> loadDbmFile(String path) throws Exception{
		Map<String,IUpdateDao> res = new HashMap<String, IUpdateDao>();
		
		SAXReader reader = new SAXReader();
		
		Document document = reader.read(path);
			
		Element root = document.getRootElement();
			
		List<Element> mapList = root.elements();
			
		for(Element e : mapList){
			String id = e.attributeValue("id");
			String className = e.elementText("class");
			String tbName = e.elementText("table");
				
			res.put(id,new DefaultUpdateDaoProxy(new DefaultUpdateDaoImpl(Class.forName(className))));
		}
			

		return res;
	}
	
}
